package com.coder.rental.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


/**
 * @author: zhanglin
 * @description:   配置MyBatisPlus的自动填充功能，在插入和更新的时候自动插入时间
 * @date 2025/3/20
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //插入时候填充
    @Override
    public void insertFill(MetaObject metaObject) {

        this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);

    }

    //更新时候填充
    @Override
    public void updateFill(MetaObject metaObject) {

        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now,LocalDateTime.class);

    }
}
